import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class StringValidator {

    public static void main(String[] args) {
        // 测试数据
        String[] testStrings = {"123", "123.4", "123.4567", "123.45678", "-123.4567", "0.1234"};

        // 正则表达式定义
        String regex = "^\\d+(\\.\\d{1,4})?$";

        // 创建Pattern对象
        Pattern pattern = Pattern.compile(regex);

        // 遍历测试数据并进行校验
        for (String s : testStrings) {
            Matcher matcher = pattern.matcher(s);
            if (matcher.matches()) {
                System.out.println(s + " 是有效的");
            } else {
                System.out.println(s + " 不是有效的");
            }
        }
    }
}